package org.kfive.nova.test.service.impl;

import org.kfive.nova.test.alphadao.UserDao;
import org.kfive.nova.test.betadao.AddressDao;
import org.kfive.nova.test.model.Address;
import org.kfive.nova.test.model.User;
import org.kfive.nova.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

/*
* UserServiceImpl.java
* Created  by  dell
* Created on 2016/3/28 15:46
*/
@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserDao userDao;

    @Autowired
    private AddressDao addressDao;


    public Integer save(User user, Address address) {
        Assert.notNull(user,"用户不能为空");
        Assert.notNull(address,"地址不能为空");

        Integer addressId = this.addressDao.save(address);
        Assert.notNull(addressId,"地址保存失败");
        user.setAddressId(addressId);
        Integer userId = this.userDao.save(user);
        Assert.notNull(userId,"用户保存失败");
        return userId;
    }

    @Override
    public Integer saveUser(User user) {
        Assert.notNull(user,"用户不能为空");
        Integer userId = this.userDao.save(user);
        Assert.notNull(userId,"用户保存失败");
        return userId;
    }


}
